import { VNode } from "vue";
import { authInterface } from "./auth.interface";
// 表格服务
export interface tableServiceInterface {
  getTable(e: any): Promise<any>; //获取表格信息
  delete?(e: any): Promise<any>; //删除表格信息
  edit?(e: any): Promise<any>; //编辑表格行信息
  add?(e: any): Promise<any>; //新增表格信息
  detail?(e: any): Promise<any>; //表格信息详情
  deleteMultiple?(e: any): Promise<any>; //批量删除
}

// 工具栏方法
export interface toolbarHandlerInterface {
  roles?: string | authInterface;
  permissions?: string | authInterface;
  handler: () => void;
}

// 工具栏
export interface toolbarInterface {
  left: Array<string | JSX.Element>;
  right: Array<string | JSX.Element>;
  [key: string]: Array<string | JSX.Element> | toolbarHandlerInterface;
}

type Breakpoint = 'xxxl' | 'xxl' | 'xl' | 'lg' | 'md' | 'sm' | 'xs';

// 表格列
export interface columnInterface {
  align?: "left" | "right" | "center";
  colSpan?: number;
  customCell?: (record: { [key: string]: any }, rowIndex: number, column: { [key: string]: any }) => void;
  customFilterDropdown?: boolean;
  customHeaderCell?: (column: { [key: string]: any }) => void;
  customRender?: (
    { text, record, index, column }
      :
      { text: string, record: { [key: string]: any }, index: number, column: { [key: string]: any } }
  ) => void;
  dataIndex?: string | string[];
  defaultFilteredValue?: string[];
  defaultSortOrder?: "ascend" | "descend";
  ellipsis?: boolean | { showTitle?: boolean };
  filterDropdown?: VNode;
  filterDropdownVisible?: boolean;
  filtered?: boolean;
  filteredValue?: string[];
  filterIcon?: VNode | ((
    { filtered, column }
      :
      { filtered: boolean, column: { [key: string]: any } }
  ) => VNode);
  filterMode?: "menu" | "tree";
  filterMultiple?: boolean;
  filters?: object[];
  filterSearch?: boolean;
  fixed?: boolean | "left" | "right";
  key?: string;
  maxWidth?: number;
  minWidth?: number;
  resizable?: boolean;
  responsive?: Breakpoint[];
  showSorterTooltip?: boolean | any;
  sortDirections?: Array<"ascend" | "descend">;
  sorter?: () => void | boolean;
  sortOrder?: "ascend" | "descend" | boolean;
  title?: string;
  width?: string | number;
  onFilter?: () => void;
  onFilterDropdownVisibleChange?: (visible: boolean) => void;
  auth?: string | authInterface;
}

type searchFormItemType = 'input' | 'radios' | 'checkbox' | 'select' | 'select_multiple' | 'select_tree' | 'switch' | 'date' | 'date_range' | 'customer';

export interface searchFormItemDataInterface {
  label: string;
  value: any;
}

// 搜索项
export interface searchFormItemInterface {
  auth?: string | authInterface;
  type: searchFormItemType;
  width?: string;
  label: string;
  change?: (
    { value, form, field }
      :
      { value: any, form: { [key: string]: any }, field: searchFormItemInterface }
  ) => void;
  attrs?: { [key: string]: any };
  datas?: searchFormItemDataInterface[];
  el?: (form: { [key: string]: any }, e: string) => JSX.Element;
  br?: boolean;
  format?: (e: any) => any;
}
export interface searchFormInterface {
  [key: string]: searchFormItemInterface;
}

// 单表格
export interface tableInterface {
  title: string; //标题
  rowKey: string; //行主键key
  toolbar?: toolbarInterface; //工具栏
  columns: columnInterface[]; //列表项
  searchForm?: searchFormInterface; //搜索项
  query?: { [key: string]: any }; //额外搜索条件
  service?: tableServiceInterface; //表格服务
  otherAttrs?: { [key: string]: any }; //表格额外属性
  pagination?: boolean; //开启分页
  bodyCell?: (
    { text, record, index, column }
      :
      { text: string, record: { [key: string]: any }, index: number, column: { [key: string]: any } }
  ) => JSX.Element | (() => JSX.Element);
  operationWidth?: string;
  operation?: ({ text, record, index, column }:
    { text: string, record: { [key: string]: any }, index: number, column: { [key: string]: any } }) => Array<{
      type: 'add' | 'edit' | 'delete' | 'detail' | 'custom',
      el?: JSX.Element;
      size?: undefined | 'large' | 'middle' | 'small',
      icon?: undefined | string | JSX.Element,
      color?: undefined | 'primary' | 'success' | 'info' | 'warning' | 'danger' | 'error' | string,
      text?: undefined | string,
      clickHandler?: 'delete' | (({ text, record, index, column }: { text: string, record: any, index: number, column: any }) => void),
      roles?: string | authInterface,
      permissions?: string | authInterface,
      hidden?: boolean,
    }>;
  popups?: Array<{ ref: string, dom: () => JSX.Element }>;
  tableSourceFormat?: {
    data?: string;
    total?: string;
    pageSize?: string;
    current?: string;
  }
}

// 多表格
export interface tablesInterface {
  list: tableInterface[];
}